home *** CD-ROM | disk | FTP | other *** search
- Path: news.lightlink.com!usenet
- From: jkramer@lightlink.com (Justin Kramer AKA Tinman)
- Newsgroups: comp.lang.c++
- Subject: Computer hangs at the end of this when run. (iostreams and fstreams)
- Date: 17 Apr 1996 03:26:06 GMT
- Organization: Justin Kramer
- Message-ID: <4l1oce$18s@majesty.lightlink.com>
- NNTP-Posting-Host: port44.lightlink.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.3
-
- Hi,
-
- I JUST started to program in C++ with iostreams and I've started
- off with an odd problem. When the following program is run, it hangs
- after everything has executed. When I took out the 'f << s;' it ran
- without crashing. Here's the source:
-
-
- #include <iostream.h>
- #include <constrea.h>
- #include <fstream.h>
-
- int main(void)
- {
- conbuf console;
-
- console.textcolor(7);
- console.textbackground(0);
- console.clrscr();
-
- cout << "Enter a line of text:\n";
-
- char *s;
- cin.getline(s, 80);
- char *fname;
- cout << "Enter file name to store that line of text in: ";
- cin.getline(fname, 79);
-
- ofstream f(fname);
- if (!f)
- cerr << "Couldn't open " << fname << "\n";
- f << s;
- f.close();
-
- cout << "\"" << s << "\"" << " written to file: " << fname <<
- "\n";
-
- cin.get();
-
- return 0;
-
- }
-
- I'm using BC++ 3.1 f that matters. Thanks in advance for any
- help.
-
-
- -tin
-
-